//
//  ST_DisposeInviteBottomToolView.swift
//  btvideo
//
//  Created by mac on 2020/12/10.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit


class ST_DisposeInviteBottomToolView: UIControl {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.clipsToBounds = true
        
        self.backgroundColor = .clear
        self.addSubview(bk_image_view)
        bk_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 0, bottom: -20, right: 0))
        }
        
        let offset = TIANCompatibleValue(value: 50)
        
        self.addSubview(left_btn)
        left_btn.snp.makeConstraints { (make) in
            make.width.equalTo(72)
            make.height.equalTo(72+30)
            make.top.equalToSuperview().offset(20)
            make.right.equalTo(self.snp.centerX).offset(-offset)
        }
        
        self.addSubview(right_btn)
        right_btn.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.centerX).offset(offset)
            make.top.width.height.equalTo(left_btn)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var bk_image_view:UIImageView = {
        let control = UIImageView()
        control.cornerRadius = 20
        control.backgroundColor = UIColor.init(white: 0, alpha: 0.3)
        return control
    }()
    
    
    fileprivate lazy var left_btn:ST_VerticalButton = {
        
        let control = ST_VerticalButton()
        
        control.image_view_edges = UIEdgeInsets.init(top: 0, left: 0, bottom: 10+20, right: 0)
        
        control.title_bottom_offset = -5
        
        let attrString = NSMutableAttributedString(string: "拒绝")
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        control.setTitleForAllStates(attrString)
        
        control.addTarget(self, action: #selector(left_click), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    fileprivate let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor.white]
    
    fileprivate lazy var right_btn:ST_VerticalButton = {
        
        let control = ST_VerticalButton()
        
        control.image_view_edges = UIEdgeInsets.init(top: 0, left: 0, bottom: 10+20, right: 0)
        
        control.title_bottom_offset = -5
        
        let attrString = NSMutableAttributedString(string: "接听")
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        control.setTitleForAllStates(attrString)
        
        control.addTarget(self, action: #selector(right_click), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    
//     
    func set(left_btn_image:UIImage,rightBtnImage:UIImage){
        
        left_btn.setImageForAllStates(left_btn_image)
        
        right_btn.setImageForAllStates(rightBtnImage)
     
    }
    
    var left_closure:((Bool)->())?
    @objc fileprivate func left_click(){
        
        left_btn.isSelected.toggle()
        
        left_closure?(left_btn.isSelected)
    }
    
    
    var right_closure:((Bool)->())?
    @objc fileprivate func right_click(){
        
        right_btn.isSelected.toggle()
        
        right_closure?(right_btn.isSelected)
    }
}
